package sample.view;

import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import sample.utils.AlertUtils;
import sample.utils.StringUtils;


public class RegisterController {

    @FXML
    private GridPane gridPane;

    @FXML
    private TextField username;

    @FXML
    private TextField verifyCode;

    @FXML
    private PasswordField password;
    @FXML
    private Label tips;
    private String serverVerifyCode;

    @FXML
    public void handleRegister(){
        String u = username.getText();
        String p = password.getText();
        String v = verifyCode.getText();

        if(StringUtils.isEmpty(u)) {
            tips.setText("手机号不能为空");
            return;
        }
        if(StringUtils.isEmpty(p)) {
            tips.setText("密码不能为空");
            return;
        }

        if(!serverVerifyCode.equals(v)) {
            tips.setText("验证码错误");
            return;
        }

        // 请求服务端 FIXME
        AlertUtils.alert("注册成功", "注册成功，服务端还没写呢，别着急", (Stage)gridPane.getScene().getWindow());
        handleCancel();
    }

    @FXML
    public void handleCancel(){
        Stage stage = (Stage) gridPane.getScene().getWindow();
        stage.close();
    }

    @FXML
    public void getVerifyCode(){
        this.serverVerifyCode = "1234";
    }
}
